import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home/Home.vue'
//异步
const Hesuan =()=>import('../views/Hesuan/index.vue')
Vue.use(VueRouter)
//先把VueRouter原型对象的push/replace先保存一份
let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;
//重写push|replace方法
// 1.location传递的哪些参数，告诉原来的push，往哪里跳转 2.resolve:成功回调， 3.失败回调
VueRouter.prototype.push = function (location, resolve, reject) {
    if (resolve && reject) {
        //call||apply区别：相同点都可以调用函数，都可以篡改函数this上下文
        //不同点：传递参数的不同，call传递参数用逗号隔开，apply数组
        originPush.call(this, location, resolve, reject)
    } else {
        originPush.call(this, location, () => { }, () => { })
    }
};
VueRouter.prototype.place = function (location, resolve, reject) {
    if (resolve && reject) {
        //call||apply区别：相同点都可以调用函数，都可以篡改函数this上下文
        //不同点：传递参数的不同，call传递参数用逗号隔开，apply数组
        originReplace.call(this, location, resolve, reject)
    } else {
        originReplace.call(this, location, () => { }, () => { })
    }
};
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/hesuan',
    name: 'Hesuan',
    component: Hesuan
  },
  {
    path: '/area',
    name: 'Area',
    component: ()=>import('../views/Area/index.vue')
  },
  {
    path: '/prevention',
    name: 'Prevention',
    component: ()=>import('../views/Prevention/index.vue')
  },
  {
    path: '/citys/:cityname',
    props:true,
    name: 'Citys',
    component: ()=>import('../views/Citys/Citys.vue')
  },
  {
    path: '/travel',
    name: 'Travel',
    component: ()=>import('../views/Travel/Travel.vue')
  },
  {
    path: '/selectCity',
    name: 'SelectCity',
    component: ()=>import('../views/SelectCity/SelectCity.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: ()=>import('../views/Login/Login.vue')
  },
  {
    path: '/register',
    name: 'Register',
    component: ()=>import('../views/Register/Register.vue')
  },
]

const router = new VueRouter({
  routes
})

export default router
